package com.ytjj.qmyx.admin.controller.supplyChain;

import com.alibaba.fastjson.JSONObject;
import com.ytjj.common.utils.HttpClientUtil;
import com.ytjj.qmyx.admin.config.SupplyApiConfig;
import com.ytjj.qmyx.admin.model.request.FreigRequest;
import com.ytjj.qmyx.admin.model.request.YxFreightTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 供应链运费模板
 */
@RestController
@RequestMapping("/freightTemplate")
@Slf4j
public class FreightTemplateController {

    @Autowired
    private SupplyApiConfig supplyApiConfig;

    /**
     * 模板列表
     * @return
     */
    @PostMapping("/page")
    public String selectFreightTemplatePage(@RequestBody FreigRequest freigRequest) {
        String s = HttpClientUtil.doPostJson(supplyApiConfig.getUrl() + "/freightTemplate/page",
                JSONObject.toJSONString(freigRequest), supplyApiConfig.getHeadsMap());
        return s;
    }
    /**
     * 模板详情
     * @return
     */
    @GetMapping("/selectYxFreightTemplate")
    public String selectFreightTemplateResponse(@RequestParam Integer id) {
        Map<String,String> map = new HashMap<>();
        map.put("id",id.toString());
        String s = HttpClientUtil.doGet(supplyApiConfig.getUrl() + "/freightTemplate/selectYxFreightTemplate",
                map, supplyApiConfig.getHeadsMap());
        return s;
    }

    /**
     * 新增运费模板
     *
     * @return
     */
    @PostMapping("/insertFreightTemplate")
    public String insertFreightTemplate(@RequestBody YxFreightTemplate yxFreightTemplate)  {
        String s = HttpClientUtil.doPostJson(supplyApiConfig.getUrl() + "/freightTemplate/insertFreightTemplate",
                JSONObject.toJSONString(yxFreightTemplate), supplyApiConfig.getHeadsMap());
        return s;
    }

    //根据省份id集
    @GetMapping("/getCitysBypids")
    public String getCitysBypids(@RequestParam(value="pids",required=false) String pids) {
        Map<String,String> map = new HashMap<>();
        map.put("pids",pids);
        String s = HttpClientUtil.doGet(supplyApiConfig.getUrl() + "/freightTemplate/getCitysBypids",
                map, supplyApiConfig.getHeadsMap());
        return s;
    }
}
